﻿namespace NKernel.Core.Impl
{
    using System;
    using System.Collections.Generic;

    using log4net;

    //using NetMX;
    //FIXME - Need to first fix NetMX to handle objects with multiple interfaces
    internal class NetMxContainer
    {
        #region Fields

        private readonly ILog logger = LogManager.GetLogger(typeof(NetMxContainer));

        #endregion Fields

        #region Constructors

        public NetMxContainer()
        {
            //mbeanServer = MBeanServerFactory.CreateMBeanServer();
        }

        #endregion Constructors

        #region Methods

        public void Register(DefaultKernelImplMBean kernel)
        {
            logger.Debug("Registering IKernel...");
            //try
            //{
            //    var name = new ObjectName(string.Format("NKernel:Name=Kernel,Type={0}",
            //        kernel.GetType()));
            //    mbeanServer.RegisterMBean(kernel, name);
            //}
            //catch (Exception exception)
            //{
            //    logger.Error(String.Format("NetMXContainer error encountered when registering IKernel instance {0}",
            //        kernel), exception);
            //}
        }

        public void RegisterComponents(IList<IComponentObject> objects)
        {
            //foreach (IComponentObject componentObject in objects)
            //{
            //    logger.DebugFormat("Registering component: {0}", componentObject.ComponentName);

            //    try
            //    {
            //        var name = new ObjectName(string.Format("NKernel:Name={0},Interface={1},Impl={2},Version={3}",
            //            componentObject.ComponentName,
            //            componentObject.ComponentInterface,
            //            componentObject.ComponentImplementation,
            //            componentObject.ComponentVersion));
            //        mbeanServer.RegisterMBean(componentObject.ComponentInterfaceInstance, name);
            //    }
            //    catch (Exception exception)
            //    {
            //        logger.Error(String.Format("NetMXContainer error encountered for component {0}",
            //            componentObject.ComponentName), exception);
            //    }
            //}
        }

        #endregion Methods

        #region Other

        //private readonly IMBeanServer mbeanServer;

        #endregion Other
    }
}